package com.sunjob.mrotech.controller;
import com.sunjob.common.domain.tech.*;
import com.sunjob.common.mroAnno.ControllerLog;
import com.sunjob.common.mroAnno.LogModuleType;
import com.sunjob.common.result.Result;
import com.sunjob.mrotech.mapper.RepairProcessMapper;
import com.sunjob.mrotech.server.RepairProcessServer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author : xiaozhoutongxue
 * @date : 2022/8/19 17:32
 */
@RestController
@Api(tags = "一级修程工艺处理")
@CrossOrigin
public class RepairProcessController {

    @Autowired
    RepairProcessServer repairProcessServer;
    @Autowired
    RepairProcessMapper repairProcessMapper;

    @ApiOperation("获得拥有修程工艺的前几个一级构型")
    @GetMapping("/getRepairProcessByLimit3")
    public Result getRepairProcessByLimit3() {
        List<TransShape> repairProcess = repairProcessServer.getRepairProcessByLimit3();
        return repairProcess.size()!=0 ?Result.ok(repairProcess, "ok"):Result.build(null,211,"未找到修程工艺");
    }

    @ApiOperation("根据一级构型id获得修程工艺")
    @GetMapping("/getRepairProcessById")
    public Result getRepairProcessById(@RequestParam Long shapeId) {
        RepairProcess repairProcess = repairProcessServer.getRepairProcessByShapeId(shapeId);
        return repairProcess!=null ?Result.ok(repairProcess, "ok"):Result.build(null,211,"未找到修程工艺");
    }
    @ApiOperation("根据一级修程工艺id获得修程工艺")
    @GetMapping("/getRepairProcessByRepairId")
    public Result getRepairProcessByRepairId(@RequestParam Long repairProcessId) {
        RepairProcess repairProcess = repairProcessMapper.getRepairProcessById(repairProcessId);
        return repairProcess!=null ?Result.ok(repairProcess, "ok"):Result.build(null,211,"未找到修程工艺");
    }

    @ApiOperation("新增一级修程工艺")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PostMapping("/insertRepairProcess")
    public Result insertRepairProcess(@RequestBody RepairProcess repairProcess) {
        String flag = repairProcessServer.insertRepairProcess(repairProcess);
        return "true".equals(flag) ? Result.ok(null, "新增成功") : Result.fail(flag);
    }

    @ApiOperation("绑定一级修程工艺通过一级构型id")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PutMapping("/bindRepairProcessByShapeId")
    public Result bindRepairProcessByShapeId(@RequestParam Long shapeId,@RequestParam Long repairProcessId){
        Boolean flag = repairProcessServer.bindRepairProcessByShapeId(shapeId,repairProcessId);
        return flag  ? Result.ok(null, "绑定成功") : Result.fail("绑定失败");
    }

    @ApiOperation("根据一级修程工艺id删除一个一级修程工艺")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @DeleteMapping("/deleteRepairProcessById")
    public Result deleteRepairProcessById(@RequestParam Long repairProcessId){
        String res = repairProcessServer.deleteRepairProcessById(repairProcessId);
        return "true".equals(res) ? Result.ok(null, "成功") : Result.build(null,210,res);
    }

    @ApiOperation("更新一个一级修程工艺(小修改：不涉及到步骤改动)")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PutMapping("/uptateRepairProcessSmall")
    public Result uptateRepairProcessSmall(@RequestBody RepairProcessDO repairProcessDO){
        Boolean flag = repairProcessServer.uptateRepairProcessSmall(repairProcessDO);
        return flag  ? Result.ok(null, "成功") : Result.fail("失败");
    }

    @ApiOperation("更新一个一级修程工艺(大修改：涉及到步骤改动，更新版本号)")
    @ControllerLog(LogModuleType.TECHNOLOGY)
    @PutMapping("/uptateRepairProcessBig")
    public Result uptateRepairProcessBig(@RequestBody RepairProcess repairprocess){
        Boolean flag = repairProcessServer.uptateRepairProcessBig(repairprocess);
        return flag  ? Result.ok(null, "成功") : Result.fail("失败");
    }
}
